package jenetics.test;

import java.util.function.Function;

import org.jenetics.BitChromosome;
import org.jenetics.BitGene;
import org.jenetics.Genotype;

public final class FF implements Function<Genotype<BitGene>, Double> {

	private final Item[] items;
	private final double size;
	
	
	public FF(Item[] items, double size) {
		this.items = items;
		this.size = size;
	}


	@Override
	public Double apply(final Genotype<BitGene> gt) {
		final Item sum = ((BitChromosome)gt.getChromosome()).ones().mapToObj(i -> items[i]).collect(Item.toSum());
		return sum.size <= this.size ? sum.value : 0;
	}

}
